﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;

namespace DC.DCAttribute.Demo
{
    class Program
    {
        static void Main(string[] args)
        {
            StartServiceHost();
        }

        private static void StartServiceHost()
        {
            //using (ServiceHost host = new ServiceHost(typeof(DC.DCAttribute.Demo.Services), new Uri("http://localhost:8001/SerializableService/")))
            //{
            //    if (host.Description.Behaviors.Find<ServiceMetadataBehavior>() == null)
            //    {
            //        ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
            //        behavior.HttpGetEnabled = true;

            //        behavior.HttpGetUrl = new Uri("http://localhost:8001/SerializableService/metadata");
            //        host.Description.Behaviors.Add(behavior);
            //    }

            //    //Add Endpoint
            //    host.AddServiceEndpoint(typeof(DC.DCAttribute.Demo.IContract), new WSHttpBinding(), "");
            //    host.CloseTimeout = TimeSpan.FromSeconds(10);

            //    host.Open();
            //    Console.WriteLine("Host started");
            //    Console.ReadKey();
            //    host.Close();
            //}

            //测试契约推断
            using (ServiceHost serviceHost = new ServiceHost(typeof(DC.DCAttribute.Demo.Services1), new Uri("http://localhost:8002/SerializableService/")))
            {
                if (serviceHost.Description.Behaviors.Find<ServiceMetadataBehavior>() == null)
                {
                    ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
                    behavior.HttpGetEnabled = true;
                    behavior.HttpGetUrl = new Uri("http://localhost:8002/SerializableService/");
                    serviceHost.Description.Behaviors.Add(behavior);
                }

                serviceHost.AddServiceEndpoint(typeof(DC.DCAttribute.Demo.IContract1), new WSHttpBinding(), "");
                serviceHost.Open();

                Console.WriteLine("serviceHost started");
                Console.ReadKey();
                serviceHost.Close();

            }
        }
    }
}
